<?php

require_once('../include/MySugarApplication.php');
require_once("../include/Account.php");
session_start();
$app->checkSession('Accounts/Form.phpl', $server_unique_key);

$actionType = isset($_REQUEST['actionType']) ? $_REQUEST['actionType'] : "";

$id = "";
$name = "";
$website = "";
$ticker_symbol = "";
$ownership = "";
$industry = "";
$account_type = "";
$employees = "";
$rating = "";
$sic_code = "";
$annual_revenue = "";
$phone_office = "";
$phone_fax = "";
$phone_alternate = "";
$email1 = "";
$billing_address_street = "";
$billing_address_city = "";
$billing_address_state = "";
$billing_address_postalcode = "";
$billing_address_country = "";
$shipping_address_street = "";
$shipping_address_city = "";
$shipping_address_state = "";
$shipping_address_postalcode = "";
$shipping_address_country = "";
$description = "";
$date_modified = "";


if ($actionType == "UPDATE") {

	$query=' accounts.id = "'.$_REQUEST["id"].'"';

	$rows = $component->getRecord($query);

	foreach($rows as $record) {
							
		$id = $record["id"];
		$name = $record["name"];
		$website = $record["website"];
		$ticker_symbol = $record["ticker_symbol"];
		$ownership = $record["ownership"];
		$industry = $record["industry"];
		$account_type = $record["account_type"];
		$employees = $record["employees"];
		$rating = $record["rating"];
		$sic_code = $record["sic_code"];
		$annual_revenue = $record["annual_revenue"];
		$phone_office = $record["phone_office"];
		$phone_fax = $record["phone_fax"];
		$phone_alternate = $record["phone_alternate"];
		$email1 = $record["email1"];
		$billing_address_street = $record["billing_address_street"];
		$billing_address_city = $record["billing_address_city"];
		$billing_address_state = $record["billing_address_state"];
		$billing_address_postalcode = $record["billing_address_postalcode"];
		$billing_address_country = $record["billing_address_country"];
		$shipping_address_street = $record["shipping_address_street"];
		$shipping_address_city = $record["shipping_address_city"];
		$shipping_address_state = $record["shipping_address_state"];
		$shipping_address_postalcode = $record["shipping_address_postalcode"];
		$shipping_address_country = $record["shipping_address_country"];
		$description = $record["description"];
		$date_modified = $record["date_modified"];
#		$created_by = $record["created_by"];
	}
}




?>
<!DOCTYPE HTML SYSTEM "http://www.bitzermobile.com/bitzer/dtd/HTML401-loose-bitzer.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<?php
		if (!$isBitzer) {
        	echo '
			<title>MySugar Accounts</title>
			<LINK REL=StyleSheet HREF="',$app->appRoot,'include/style.css" TYPE="text/css" MEDIA=screen>
        <script type="text/javascript" src="',$app->appRoot,'include/niftycube.js"></script>
        <script type="text/javascript">
            window.onload=function(){
				var width = "550px";
				setAppRoot("',$app->appRoot,'");
                Nifty("div#container");
                Nifty("div#content,div#nav","same-height small");
                Nifty("div#header,div#footer","small");
                Nifty("ul.postnav a","transparent");
				setWidth("div#container", width);
				setWidth("div#content", width);
				setWidth("div#footer", width);
            }
        </script>';
        } else {
			echo '<title></title>';
		}
			?>    
    </head>
    <body>
    	<?php
		if (!$isBitzer) {
			echo '
        <div id="container">
            <div id="header">
				<table width="100%">
					<tr>
						<td width="95%"><h1>Accounts</h1></td>
						<td align="right" width="5%"><a href="',$app->appRoot,'Logout.php">Logout</a></td>
					</tr>
				</table>
			</div>
            <div id="content">
                <h3>Please enter account info.</h3>';
		}
		?>
                <form name="Accounts"
                      data-bitzer-title="Account"
                      data-bitzer-desc="Accounts"
                      data-bitzer-type="COMPONENT"
                      data-bitzer-data-url="<?php echo $app->appRoot ?>Accounts/Data.php"
		      data-bitzer-sync-scheme="WEBAPP_SOFT"
		      data-bitzer-detail-table-id="accountDetailComponents"
                      data-bitzer-pagination="true"
		      data-bitzer-online-only="false"
		      data-bitzer-read-only="false"
                      data-bitzer-last-modified="2010-03-26 00:00:00 EST"
                      action="Save.php" method="post"
                      enctype="application/x-www-form-urlencoded">
                    <input type="hidden" name="id" value="<?php echo $id ?>"
                           data-bitzer-primary-key="true"
                           data-bitzer-type="string">
                    <?php 
                    	if ($actionType == "UPDATE" ) {
                    		echo '<input type="hidden" name="actionType" value="UPDATE">';
                    	}
                    ?>
<?php
if (!$isBitzer) {
?>
                    <table class="form" width="100%">
                        <tr>
                            <th width="27%">
                                <div align="left">
                                    Name
                                </div>
                            </th>
                            <td>
<?php
}
?>
                                <input data-bitzer-label="Account Name"
                                       data-bitzer-short-label="Name"
                                       data-bitzer-type="string"
                                       data-bitzer-help-text="Name of account"
                                       placeholder="Enter account name"
                                       type="text" name="name"
                                       size="50"
                                       data-bitzer-default-view-column="1"
                                       data-bitzer-display-group-name="Info"
                                       data-bitzer-display-group-order="1"
                                        data-bitzer-display-group-title="" 
                                       
                                       value="<?php echo $name ?>" >
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Website
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Website"
                                       data-bitzer-short-label="Web"
                                       data-bitzer-help-text="Website URL"
                                       data-bitzer-type="url"
                                       placeholder="Company URL"
                                       type="text" name="website"
                                       data-bitzer-display-group-name="Info"
                                       size="50"
                                       value="<?php echo $website ?>">
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Ticker Synbol
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Ticker Symbol"
                                       data-bitzer-short-label="Ticker"
                                       data-bitzer-help-text="Ticker symbol"
                                       data-bitzer-type="string"
                                       type="text" name="ticker_symbol"
                                       data-bitzer-display-group-name="Info"
                                       size="50"
                                       value="<?php echo $ticker_symbol ?>">
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Ownership
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Ownership"
                                       data-bitzer-short-label="Ownership"
                                       data-bitzer-help-text="Ownership"
                                       data-bitzer-type="string"
                                       type="text" name="ownership"
                                       data-bitzer-display-group-name="Info"
                                       size="50"
                                       value="<?php echo $ownership ?>">
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Industry
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <select data-bitzer-label="Industry"
                                        data-bitzer-short-label="Industry"
                                        data-bitzer-type="string"
                                        data-bitzer-help-text="Industry of account" 
                                        data-bitzer-display-group-name="Info"
                                        name="industry"  >
                                <?php
									foreach ($industriesArray as $key => $label) {
									
										if ($label == $industry)
											$selected = "SELECTED";
										else
											$selected = "";
								
										echo '<option value="',$key,'" ',$selected,' >',$label,'</option>';
									}
								?>
                                	
                                </select>
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Account Type
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <select data-bitzer-label="Account Type"
                                        data-bitzer-short-label="Account"
                                        data-bitzer-type="string"
                                        data-bitzer-help-text="Type of Account" 
                                        data-bitzer-display-group-name="Info"
                                        name="account_type"  >
                                <?php
									foreach ($accountTypesArray as $key => $label) {
									
										if ($label == $account_type)
											$selected = "SELECTED";
										else
											$selected = "";
								
										echo '<option value="',$key,'" ',$selected,' >',$label,'</option>';
									}
								?>
                                	
                                </select>
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th width="27%">
                                <div align="left">
                                    Employees
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Employees"
                                       data-bitzer-short-label="Employees"
                                       data-bitzer-type="integer"
                                       data-bitzer-help-text="Number of employees"
                                       data-bitzer-display-group-name="Info"
                                       type="text" name="employees"
                                       size="50"
                                       value="<?php echo $employees ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Rating
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Rating"
                                       data-bitzer-short-label="Rating"
                                       data-bitzer-help-text="Account rating"
                                       data-bitzer-type="string"
                                       data-bitzer-display-group-name="Info"
                                       type="text" name="rating"
                                       size="50"
                                       value="<?php echo $rating ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    SIC Code
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="SIC Code"
                                       data-bitzer-short-label="SIC"
                                       data-bitzer-help-text="SIC Code for account"
                                       data-bitzer-type="string"
                                       data-bitzer-display-group-name="Info"
                                       type="text" name="sic_code"
                                       size="50"
                                       value="<?php echo $sic_code ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Annual Revenue
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Annual Revenue"
                                       data-bitzer-short-label="Revenue"
                                       data-bitzer-help-text="Annual reveneu of account"
                                       data-bitzer-display-group-name="Info"
                                       data-bitzer-type="currency"
                                       data-bitzer-currency-symbol="$"
                                       type="text" name="annual_revenue"
                                       size="50"
                                       value="<?php echo $annual_revenue ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                       <tr>
                            <th>
                                <div align="left">
                                    Office Phone
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Office Phone"
                                	   data-bitzer-short-label="Office"
                                       data-bitzer-help-text="Office Phone of account"
                                       data-bitzer-display-group-name="Contact"
                                       data-bitzer-display-group-order="2"
                                       data-bitzer-display-group-title="Contact Information"
                                       data-bitzer-type="tel"
                                       type="text" name="phone_office"
                                       size="50"
                                       value="<?php echo $phone_office ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Fax
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Fax"
                                       data-bitzer-short-label="Fax"
                                       data-bitzer-help-text="Fax number for account"
                                       data-bitzer-display-group-name="Contact"
                                       data-bitzer-type="fax"
                                       type="text" name="phone_fax"
                                       size="50"
                                       value="<?php echo $phone_fax ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Other Phone
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Other Phone"
                                       data-bitzer-short-label="Other"
                                       data-bitzer-help-text="Alternate phone for account"
                                       data-bitzer-display-group-name="Contact"
                                       data-bitzer-type="tel"
                                       type="text" name="phone_alternate"
                                       size="50"
                                       value="<?php echo $phone_alternate ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Email
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Email"
                                       data-bitzer-help-text="Email of account"
                                       data-bitzer-type="email"
                                       data-bitzer-display-group-name="Contact"
                                       type="text" name="email1"
                                       size="50"
                                       value="<?php echo $email1 ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Billing Street
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Street"
                                	   data-bitzer-short-label="Street"
                                       data-bitzer-help-text="Billing street"
                                       data-bitzer-type="street"
                                       type="text" name="billing_address_street"
                                       data-bitzer-display-group-name="billing"
                                       data-bitzer-display-group-order="3"
                                       data-bitzer-display-group-title="Billing Address"
				       data-bitzer-display-group-type="address"
                                       size="50"
                                       value="<?php echo $billing_address_street ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Billing City
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="City"
                                	   data-bitzer-short-label="City"
                                       data-bitzer-help-text="Billing city"
                                       data-bitzer-type="city"
                                       type="text" name="billing_address_city"
                                       data-bitzer-display-group-name="billing"
                                       size="50"
                                       value="<?php echo $billing_address_city ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
         				                        <tr>
                            <th>
                                <div align="left">
                                    Billing State
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="City"
                                	   data-bitzer-short-label="City"
                                       data-bitzer-help-text="Billing city"
                                       data-bitzer-type="state"
                                       type="text" name="billing_address_state"
                                       data-bitzer-display-group-name="billing"
                                       size="50"
                                       value="<?php echo $billing_address_state ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Billing Postal Code
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Postal Code"
                                	   data-bitzer-short-label="Zip"
                                       data-bitzer-help-text="Billing postal code or zip"
                                       data-bitzer-type="postalCode"
                                       type="text" name="billing_address_postalcode"
                                       data-bitzer-display-group-name="billing"
                                       size="50"
                                       value="<?php echo $billing_address_postalcode ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>                        
                        <tr>
                            <th>
                                <div align="left">
                                    Billing Country
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Country"
                                	   data-bitzer-short-label="Country"
                                       data-bitzer-help-text="Billing country"
                                       data-bitzer-type="country"
                                       type="text" name="billing_address_country"
                                       data-bitzer-display-group-name="billing"
                                       size="50"
                                       value="<?php echo $billing_address_country ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>                                  
                        <tr>
                            <th>
                                <div align="left">
                                    Shipping Street
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Street"
                                	   data-bitzer-short-label="Street"
                                       data-bitzer-help-text="Shipping street"
                                       data-bitzer-type="street"
                                       type="text" name="shipping_address_street"
                                       data-bitzer-display-group-name="shipping"
                                       data-bitzer-display-group-order="4"
                                       data-bitzer-display-group-title="Shipping Address"
				       data-bitzer-display-group-type="address"
                                       size="50"
                                       value="<?php echo $shipping_address_street ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Shipping City
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="City"
                                	   data-bitzer-short-label="City"
                                       data-bitzer-help-text="Shipping city"
                                       data-bitzer-type="city"
                                       type="text" name="shipping_address_city"
                                       data-bitzer-display-group-name="shipping"
                                       size="50"
                                       value="<?php echo $shipping_address_city ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                      	                        <tr>
                            <th>
                                <div align="left">
                                    Shipping State
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="State"
                                	   data-bitzer-short-label="State"
                                       data-bitzer-help-text="Shipping state"
                                       data-bitzer-type="state"
                                       type="text" name="shipping_address_state"
                                       data-bitzer-display-group-name="shipping"
                                       size="50"
                                       value="<?php echo $shipping_address_state ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Shipping Postal Code
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Postal Code"
                                	   data-bitzer-short-label="Zip"
                                       data-bitzer-help-text="Shipping postal code or zip"
                                       data-bitzer-type="postalCode"
                                       type="text" name="shipping_address_postalcode"
                                       data-bitzer-display-group-name="shipping"
                                       size="50"
                                       value="<?php echo $shipping_address_postalcode ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>                        
                        <tr>
                            <th>
                                <div align="left">
                                    Shipping Country
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Country"
                                	   data-bitzer-short-label="Country"
                                       data-bitzer-help-text="Shipping country"
                                       data-bitzer-type="country"
                                       type="text" name="shipping_address_country"
                                       data-bitzer-display-group-name="shipping"
                                       size="50"
                                       value="<?php echo $shipping_address_country ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>                        
                        <tr>
                            <th>
                                <div align="left">
                                    Description
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                            	<textarea data-bitzer-label="Description"
                                	   data-bitzer-short-label="Desc."
                                       data-bitzer-help-text="Description for account"
                                       data-bitzer-display-group-name="Description"
                                       data-bitzer-display-group-order="5"
                                       data-bitzer-display-group-title="Description"
                                       rows="5" cols="40"
									   name="description"><?php echo $description ?></textarea>
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Last Modified On
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Modified On"
                                       data-bitzer-help-text="The record was last modified on this date."
                                       data-bitzer-type="datetime"
                                       readonly
                                       type="text" name="last_modified_on" value="<?php echo $date_modified ?>" >
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                    </table>

                    <br>
                    <table>
                        <tr><td>
                                <ul class="postnav">
                                    <li><a href="javascript:document.Accounts.submit();">Save</a></li>
                                </ul>
                            </td>
                            <td>&nbsp;&nbsp;&nbsp;
                            </td>
                            <td>
                                <ul class="postnav">
                                    <li><a href="Data.php">Cancel</a></li>
                                </ul>
                            </td>
                        </tr>
                    </table>
<?php
}
?>                    
                </form>
<?php
if (!$isBitzer) {
?>
            </div>
            <div id="footer"></div>
        </div>
<?php
}
?>
<?php
if (!$isBitzer) {
?>
		<br>
		<br>
		<div id="container">
        	<div id="header">
           		<h2>Related Items</h2>
            </div>
        <div id="content">
        	<br>
<?php
}
?>
        	<table 
<?php
if (!$isBitzer) {
?>            
            border="0" cellspacing="0" cellpadding="0"
                   class="list"  width="100%"
<?php
}
?>

                   id="accountDetailComponents">
<?php
if (!$isBitzer) {
?>
            	<tr>
                	<th>Component Name</th>
                </tr>
<?php
}
?>
                <tr data-bitzer-component="Contacts" data-bitzer-linked-view="contacts-default-view">
                	<td data-bitzer-master-field="id"
                        data-bitzer-detail-field="account_id">
<?php
if (!$isBitzer) {
?>
                        	<a href="<?php echo $app->appRoot ?>Contacts/Data.php?account_id=<?php echo $id ?>">Contacts</a>
<?php
}
?>
                    </td>
                </tr>
                <tr data-bitzer-component="Leads">
                	<td data-bitzer-master-field="name"
                        data-bitzer-detail-field="account_name">
<?php
if (!$isBitzer) {
?>
                        	<a href="<?php echo $app->appRoot ?>Leads/Data.php?account_name=<?php echo $name ?>">Leads</a>
<?php
}
?>
                    </td>
                </tr>
            </table>
<?php
if (!$isBitzer) {
?>
        </div>
        <div id="footer"></div>
        <br>
<?php
}
?>
    </body>
</html>
